import {
  setUp_pay_password
} from '../../../../../api.js'
var app = getApp(); //获取App内部的信息
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lis: [1, 2, 3, 4, 5, 6],
    bank_input_bind_num: 0,
    focus_input: true,
    password: '',
    num: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var num = options.password
    this.setData({
      num: num
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '赋能奢商，只为业绩增长',
      imageUrl: "https://document.growthupup.com/growthShare.jpg?t=" + new Date().getTime(),
      path: '/pages/user/login/login',
    }
  },
  bank_input_bind: function(e) {
    var num = e.detail.value;
    var that = this
    that.setData({
      bank_input_bind_num: num.length
    })
    if (num.length > 5) {
      that.setData({
        focus_input: false,
        password: num
      })
    }
  },
  input_foc: function() {
    this.setData({
      focus_input: true
    })
  },
  confirm_btn: function() {
    var that = this
    setUp_pay_password({
      token: app.globalData.token,
      repassword: that.data.password,
      password: that.data.num
    }).then(res => {
      console.log(res.data.msg)
      if (res.data.code == 666) {
        if (wx.getStorageSync('payPassword') == 'no') {
          wx.showToast({
            title: res.data.msg,
          })
          var pages = getCurrentPages();
          var prevPage = pages[pages.length - 3];
          console.log(prevPage.data.info_batchcode)
          prevPage.setData({
            'detail.is_pay_password':1
          })
          setTimeout(function () {
            wx.navigateBack({
              delta: 2
            })
          }, 1500)
        } else {
          wx.showToast({
            title: res.data.msg,
          })
          setTimeout(function() {
            wx.redirectTo({
              url: '/pages/user/bill/putForward/putForward',
            })
          }, 1500)
        }
      } else if (res.data.code == 111111) {
        wx.showToast({
          title: '登录失效，请重新登录',
          icon: 'none',
        })
        setTimeout(function() {
          wx.reLaunch({
            url: '/pages/user/login/login',
          })
        }, 1500)
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
        that.setData({
          focus_input: true
        })
      }
    })
  }
})